<?php

namespace app\admin\controller;

use app\admin\logic\BarnLogic;
use app\common\respond\HttpApi;

class BarnController
{
    /**
     * @Description 列表
     * @author: zj
     * @param HttpApi $respond
     * @time 2024/03/05 15:22:53
     * @return \think\response\Json
     */
    public function list(HttpApi $respond)
    {
        $param = [
            'page' => (int)request()->get('page') ?: 1,
            'page_size' => (int)request()->get('page_size') ?: 10,
            'factory_id' => request()->get('factory_id'),
            'name' => request()->get('name')
        ];
        $rule = [
            'page' => 'require|>:0',
            'page_size' => 'require|>:0',
            'factory_id' => '>:0',
            'name' => 'max:30'
        ];
        validate($rule)->check($param);

        $logic = new BarnLogic();
        $data = $logic->getList($param);

        return $respond->success($data);
    }

    /**
     * @Description 详情
     * @author: zj
     * @param HttpApi $respond
     * @time 2024/03/05 15:25:22
     * @return \think\response\Json
     */
    public function detail(HttpApi $respond)
    {
        $param = [
            'id' => request()->get('id')
        ];
        $rule = [
            'id' => '>:0'
        ];
        validate($rule)->check($param);

        $logic = new BarnLogic();
        $data = $logic->detail($param['id']);

        return $respond->success($data);
    }

    /**
     * @Description 下拉选择
     * @author: zj
     * @param HttpApi $respond
     * @time 2024/03/05 15:39:02
     * @return \think\response\Json
     */
    public function selectList(HttpApi $respond)
    {
        $param = [
            'page' => (int)request()->get('page') ?: 1,
            'page_size' => (int)request()->get('page_size') ?: 10,
            'factory_id' => request()->get('factory_id'),
            'name' => request()->get('name')
        ];
        $rule = [
            'page' => 'require|>:0',
            'page_size' => 'require|>:0',
            'factory_id' => '>:0',
            'name' => 'max:30'
        ];
        validate($rule)->check($param);

        $logic = new BarnLogic();
        $data = $logic->selectList($param);

        return $respond->success($data);
    }

}